package com.ruoyi.partybuilding.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.partybuilding.common.EQueryHelper;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.partybuilding.mapper.TeamRecordMapper;
import com.ruoyi.partybuilding.domain.TeamRecord;
import com.ruoyi.partybuilding.service.ITeamRecordService;

import javax.annotation.Resource;

/**
 * 班子记录Service业务层处理
 * 
 * @author he-liangliang@outlook.com
 * @date 2024-11-27
 */
@Service
public class TeamRecordServiceImpl implements ITeamRecordService 
{
    @Autowired
    private TeamRecordMapper teamRecordMapper;

    @Resource
    protected EQueryHelper queryHelper;
    String sql="select * from pb_team_record t where year= ( select max(`year`) from pb_team_record GROUP BY dept_id HAVING dept_id=t.dept_id) and DATE_ADD(t.trans_time,INTERVAL t.year_limit year)>NOW()";

    /** 获取部门当前有效班子信息
     *
     * @param deptId
     * @return
     */
    public R<List<TeamRecord>> nowEffectiveTeam(Long deptId) {
        var re= queryHelper.CreateItems(sql)
                .andNotNull("dept_id=?", deptId)
                .resultPkg().sqlQuery(TeamRecord.class);
        return R.ok(re);
    }
    /**
     * 查询班子记录
     * 
     * @param id 班子记录主键
     * @return 班子记录
     */
    @Override
    public TeamRecord selectTeamRecordById(Long id)
    {
        return teamRecordMapper.selectTeamRecordById(id);
    }

    /**
     * 查询班子记录列表
     * 
     * @param teamRecord 班子记录
     * @return 班子记录
     */
    @Override
    public List<TeamRecord> selectTeamRecordList(TeamRecord teamRecord)
    {
        return teamRecordMapper.selectTeamRecordList(teamRecord);
    }

    /**
     * 新增班子记录
     * 
     * @param teamRecord 班子记录
     * @return 结果
     */
    @Override
    public int insertTeamRecord(TeamRecord teamRecord)
    {
        return teamRecordMapper.insertTeamRecord(teamRecord);
    }

    /**
     * 修改班子记录
     * 
     * @param teamRecord 班子记录
     * @return 结果
     */
    @Override
    public int updateTeamRecord(TeamRecord teamRecord)
    {
        return teamRecordMapper.updateTeamRecord(teamRecord);
    }

    /**
     * 批量删除班子记录
     * 
     * @param ids 需要删除的班子记录主键
     * @return 结果
     */
    @Override
    public int deleteTeamRecordByIds(Long[] ids)
    {
        return teamRecordMapper.deleteTeamRecordByIds(ids);
    }

    /**
     * 删除班子记录信息
     * 
     * @param id 班子记录主键
     * @return 结果
     */
    @Override
    public int deleteTeamRecordById(Long id)
    {
        return teamRecordMapper.deleteTeamRecordById(id);
    }
}
